package com.heima.wemedia.controller;
import com.heima.model.admin.dtos.NewsAuditDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsPageReqDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDTO wmNewsPageReqDto){
        return wmNewsService.findList(wmNewsPageReqDto);
    }

    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDTO dto){
        return wmNewsService.submit(dto);
    }

    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id){
//        System.out.println("根据id删除文章");
        return wmNewsService.deleteNews(id);
    }

    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDTO dto){
        return wmNewsService.downOrUp(dto);
    }

    @GetMapping("one/{id}")
    public ResponseResult updateNews(@PathVariable Integer id){
        return ResponseResult.okResult(wmNewsService.getById(id));
    }

    @PostMapping("list_vo")
    public ResponseResult listVo(@RequestBody NewsAuthDTO dto){
        return wmNewsService.listVo(dto);
    }

    @GetMapping("one_vo/{id}")
    public ResponseResult findNewsById(@PathVariable Integer id){
        return ResponseResult.okResult(wmNewsService.getById(id));
    }

    @PostMapping("auth_pass")
    public ResponseResult newsPass(@RequestBody NewsAuthDTO dto){
        return wmNewsService.newsPass(dto);
    }

    @PostMapping("auth_fail")
    public ResponseResult newsFail(@RequestBody NewsAuthDTO dto){
        return wmNewsService.newsFail(dto);
    }


    /**
     * 根据Id修改文章
     * @param wmNews
     * @return
     */
    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }

}